﻿@page "/SchoolOutput"
@inject SchoolClient Http
@inject IJSRuntime JS

<div style="width:100vw;height:100vh;display:flex;flex-direction:column;justify-content:center;align-items:center;">
	<Button Style="margin:10px;" Loading="@_downloading"
            OnClick="@DownloadFinishedStudents"
            Type="@ButtonType.Primary">导出完成核对学生信息总表</Button>
    <Button Style="margin:10px;" Loading="@_downloading"
            OnClick="@DownloadFinishedStudentsDivided"
            Type="@ButtonType.Primary">导出完成核对学生信息分学院表</Button>
    <Button Style="margin:10px;" Loading="@_downloading"
            OnClick="@DownloadUnfinishedStudents"
            Type="@ButtonType.Primary">导出未完成核对学生信息</Button>
    <Button Style="margin:10px;" Loading="@_downloading"
            OnClick="@DownloadSchoolStatus"
            Type="@ButtonType.Primary">导出学院完成情况信息</Button>
    <Button Style="margin:10px;" Loading="@_downloading"
            OnClick="@DownloadEmptyBeds"
            Type="@ButtonType.Primary">导出并下载空床位信息</Button>


</div>

@code {
    bool _downloading = false;

        public async Task DownloadFinishedStudents()
    {
        _downloading = true;
        var stream = await Http.GetAllStudents();
        var fileName = $"研究生住宿信息核对-{DateTime.Now:MMddHHmm}.xlsx";
        using var streamRef = new DotNetStreamReference(stream: stream);

        await JS.InvokeVoidAsync("downloadFileFromStream", fileName, streamRef);
        _downloading = false;
    }

    public async Task DownloadFinishedStudentsDivided()
    {
        _downloading = true;
        var stream = await Http.GetAllStudentsDivide();
        var fileName = $"研究生住宿信息核对-{DateTime.Now:MMddHHmm}.zip";
        using var streamRef = new DotNetStreamReference(stream: stream);

        await JS.InvokeVoidAsync("downloadFileFromStream", fileName, streamRef);
        _downloading = false;
    }

    public async Task DownloadSchoolStatus()
    {
        _downloading = true;
        var stream = await Http.GetSchoolStatus();
        var fileName = $"学院信息-{DateTime.Now:MMddHHmm}.xlsx";
        using var streamRef = new DotNetStreamReference(stream: stream);

        await JS.InvokeVoidAsync("downloadFileFromStream", fileName, streamRef);
        _downloading = false;
    }

    public async Task DownloadUnfinishedStudents()
    {
        _downloading = true;
        var stream = await Http.GetUnfinishedStudents();
        var fileName = $"未完成核对学生信息-{DateTime.Now:MMddHHmm}.xlsx";
        using var streamRef = new DotNetStreamReference(stream: stream);

        await JS.InvokeVoidAsync("downloadFileFromStream", fileName, streamRef);
        _downloading = false;
    }

    public async Task DownloadEmptyBeds()
    {
        _downloading = true;
        var stream = await Http.GetEmptyBeds();
        var fileName = $"空床位信息-{DateTime.Now:MMddHHmm}.xlsx";
        using var streamRef = new DotNetStreamReference(stream: stream);

        await JS.InvokeVoidAsync("downloadFileFromStream", fileName, streamRef);
        _downloading = false;
    }
}